<?php
/**
 * Created by PhpStorm.
 * User: gaoliang
 * Date: 2017/5/24
 * Time: 10:49
 */
require_once dirname(dirname(__FILE__)).'/common/lib/php/PHPExecl/PHPExcel.php';

$excelObj = new PHPExcel;
$excelObj->getProperties()->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");

$excelObj->setActiveSheetIndex(0)
    ->setCellValue('A1', 'sku')
    ->setCellValue('B1', '批次订单号')
    ->setCellValue('C1', '供应商回货数量')
    ->setCellValue('D1', '交货数量')
    ->setCellValue('E1', '入库数量')
    ->setCellValue('F1', '请款数量')
    ->setCellValue('G1', '回货状态')
    ->setCellValue('H1', '入库状态')
    ->setCellValue('I1', '供应商')
    ->setCellValue('J1', '采购')
    ->setCellValue('K1', '目的仓')
    ->setCellValue('L1', '需求数量')
    ->setCellValue('M1', '参考成本')
    ->setCellValue('N1', '历史最低价')
    ->setCellValue('O1', '下单时间')
    ->setCellValue('P1', '订单号')
;

// IE 与 ssl 需要的信息
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");// 时间总是过去的
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// 文件总是被修改的
header ('Cache-Control: cache, must-revalidate');
header ('Pragma: public');

//下载 xls
header('Content-Disposition: attachment;filename="TEST.xls"');

$objWriter = PHPExcel_IOFactory::createWriter($excelObj, 'Excel5');
$objWriter->save('php://output');